#!/bin/bash
# Debian中文语言包一键安装脚本 v2.1
# 作者：AI助手
# 日期：2023-10-05

# 设置颜色输出
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
NC='\033[0m'

# 检查root权限
if [ "$EUID" -ne 0 ]; then
    echo -e "${RED}错误：需要root权限运行此脚本${NC}"
    exit 1
fi

# 更新系统
echo -e "${YELLOW}正在更新系统...${NC}"
apt update && apt upgrade -y || {
    echo -e "${RED}系统更新失败，请检查网络连接${NC}"
    exit 1
}

# 安装基础语言包
echo -e "${YELLOW}安装基础语言支持...${NC}"
apt install -y locales || exit 1

# 配置locale
echo -e "${YELLOW}配置中文locale...${NC}"
{
    echo "zh_CN.UTF-8 UTF-8"
    echo "en_US.UTF-8 UTF-8"
} | tee -a /etc/locale.gen > /dev/null

# 生成locale
locale-gen || exit 1

# 设置系统语言环境
echo -e "${YELLOW}设置系统语言环境...${NC}"
echo "LANG=zh_CN.UTF-8" > /etc/environment
echo "LANGUAGE=zh_CN:zh" >> /etc/environment

# 可选组件安装（支持多选）
echo -e "\n${YELLOW}可选组件安装：${NC}"
options=(
    "1. 中文字体包" "fonts-wqy-zenhei fonts-wqy-microhei"
    "2. 输入法框架" "ibus ibus-libpinyin fcitx fcitx-sunpinyin"
    "3. GNOME桌面中文支持" "language-pack-gnome-zh-hans language-pack-gnome-zh-min"
    "4. Chromium中文支持" "chromium-l10n"
    "5. 所有推荐组件" "all"
)

# 显示选项
echo -e "\n可用选项："
for i in "${!options[@]}"; do
    if (( i % 2 == 0 )); then
        echo "  $((i/2+1)).${options[i]}"
    fi
done

# 获取用户选择
read -p "请选择要安装的组件（多个选项用空格分隔，直接回车跳过）: " choices

# 处理选择
selected=()
for choice in $choices; do
    if [[ "$choice" == "all" ]]; then
        selected=("${options[@]}")
        break
    elif (( choice >= 1 && choice <= ${#options[@]}/2 )); then
        selected+=("${options[((choice-1)*2+1)]}")
    fi
done

# 安装选中组件
if [ ${#selected[@]} -gt 0 ]; then
    echo -e "\n${YELLOW}正在安装选中的组件...${NC}"
    apt install -y ${selected[@]} || {
        echo -e "${RED}部分组件安装失败，请检查依赖关系${NC}"
    }
fi
#wikkmmxzx
sudo apt update && sudo apt install locales language-pack-zh-hans
#eoknbzaz
sudo locale-gen zh_CN.UTF-8
#eiknnbxzchjnnv
sudo dpkg-reconfigure locales
#wuiknbxzfh
sudo apt install fonts-wqy-zenhei fonts-wqy-microhei
#wyiknnnxszf
fc-cache -fv
#aschikmnbxzd
sudo apt install language-pack-gnome-zh-hans
#stijnncsdgjjj
sudo apt install fcitx5 fcitx5-chinese-addons fcitx5-frontend-gtk3
#etujnbcazfhhjbvc
sudo dpkg-reconfigure tzdata
#euikkmncxfu
locale
#adyijnnknbcx
fc-list | grep -i "wqy"
#tuiknnvssdyujj
sudo apt install xfce4-goodies xfce4-theme-arc
# 验证配置
echo -e "\n${YELLOW}验证语言配置...${NC}"
locale | grep -E 'LANG|LC_CTYPE' || {
    echo -e "${RED}语言配置验证失败，请检查/etc/locale.gen和/etc/environment${NC}"
    exit 1
}

# 完成提示
echo -e "\n${GREEN}中文支持安装完成！${NC}"
echo -e "${YELLOW}建议操作："
echo "1. 重新启动系统：${GREEN}reboot${NC}"
echo "2. 安装输入法：${GREEN}sudo apt install fcitx fcitx-pinyin${NC} 或 ${GREEN}ibus ibus-libpinyin${NC}"
echo "3. 配置区域设置：${GREEN}sudo dpkg-reconfigure locales${NC}"
echo -e "${NC}"